<%@page import="com.apache.uct.common.ToolsUtil"%>
<%@ page language="java" import="java.util.*" contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/meta.jsp" %>

<%
	String attachDomain = "";
	String attachServerUrl = "";
	String file_download_url = "";
	
	attachDomain = ToolsUtil.getInstance().getValueByKey("DOMAIN");
	attachServerUrl =  ToolsUtil.getInstance().getValueByKey("atta_server");
	file_download_url = ToolsUtil.getInstance().getValueByKey("DOWNLOAD_URL");
%>

    <script type="text/javascript">
		var ctx = "<%=attachServerUrl%>";
		
		//document.domain = '<%=attachDomain%>';
		/*
	             新无实体上传在网站或者其它外部系统使用时，需设置：
	     1.修改form表单提交地址的参数为isRemote=T
	     2.将本页面document.domain 的注释放开
	     3.在unity_config.properties中设置参数DOMAIN
		*/
     </script>
     
	<%@ include file="/common/import.jsp" %>
	<!-- <link rel="stylesheet" type="text/css" href="${ctx}/js/easyui/themes/default/easyui.css"> -->
	<script type="text/javascript" src="${ctx}/js/easyui/extendvalidate.js"></script>
	<script type="text/javascript" src="${ctx}/js/attachment/js/singeAttrUpload-1.6.js"></script>
	<script type="text/javascript">
	function clickAttaSort(type){
	   window.location.href="${ctx}/attachment/media/toSample.action?type="+type;
	}
	
	//定于全局变量,下载路径
	var downloadUrl = "";
	
	//上传文件
	function uploadFile(){
		var uploadP = $("#uploadP");
		//判断是否存在值
		if(uploadP.val() == null ||  $.trim(uploadP.val()).length == 0){
			sampleErrorMsg("请选择要上传的文件!");
			return;
		}	
		//表单提交
		document.getElementById("uploadMedia").submit();
    }

	//提示错误信息
	function sampleErrorMsg(msg){
			$.messager.alert("错误提示",msg, "error");
	}
	
	myDis = function (id,flag,msg,murl){
	  	 if(flag == "T"){
			 $.messager.alert("上传结果",msg, "info");
			 var fileDownloadUrl  = '<%=file_download_url%>';
			 var filePath_ = murl.replace(new RegExp(fileDownloadUrl), "");
			 $("#attaFilePath").val(filePath_.substr(1,filePath_.lastIndexOf("/")-1));
			 $("#attafileName").val(filePath_.substr(filePath_.lastIndexOf("/")+1,filePath_.length));
			 $("#downloadUrl").val(murl);
			 downloadUrl = murl;
		}else{
			sampleErrorMsg(msg);
		}
	};
	
	
	//点击下载时,弹出页面
	function downloadFile(){
		if(downloadUrl!=""){
			window.open(downloadUrl);
		}else{
		    sampleErrorMsg("url下载地址为空");
		}
	}
	
	
	//删除	
	function deleteFile(){
		var attaFilePath = $("#attaFilePath");
		var attafileName = $("#attafileName");
		if(attaFilePath.val() == null ||  $.trim(attaFilePath.val()).length == 0){
			sampleErrorMsg("请设置文件夹路径!");
			return;
		}	
		if(attafileName.val() == null ||  $.trim(attafileName.val()).length == 0){
			sampleErrorMsg("请设置文件名称!");
			return;
		}	
		$.ajax({
				type:'post',
				url:'${ctx}/attachment/media/delete.action',
				data:'attaFilePath='+attaFilePath.val()+'&attafileName='+attafileName.val(),
				dataType:'json',
				success:function(data){
				     if("T"==data.flag){
				     	$.messager.alert("删除结果",data.msg, "info");
				     	$("#attaFilePath").val("");
				     	$("#attafileName").val("");
				     	$("#downloadUrl").val("");
				     	downloadUrl="";
				     }else{
				     	$.messager.alert("删除结果",data.msg, "error");
				     }
					},
				error:function(){
					 $.messager.alert("删除结果","未知异常", "error");
					}
				});
	}
	</script>
	
<body  style="font-size:12px;font-family: 微软雅黑">
<span>				  
 <input type="radio" name="attaSort" value="0"   onclick="clickAttaSort('0')" />&nbsp;附件
 <input type="radio" name="attaSort" value="2"  checked=checked  onclick="clickAttaSort('2')" />&nbsp;新附件上传
 <input type="radio" name="attaSort" value="1"   onclick="clickAttaSort('1')" />&nbsp;图片
</span><br/><br/>
<div id="sampleUW" iconCls="icon-ok">
		请查看附件库下attachment-media-newsample.jsp,查看帮助,此页面多由业务部编写控制<br>
		本页面下载地址:<a href="${ctx}/js/attachment/upload/attachment-media-newsample.zip">下载</a>
			<form target="uploadIframe" name="uploadMedia" id="uploadMedia" action="${ctx}/attachment/media/upload.action?isRemote=F" method="POST" enctype="multipart/form-data">
				<input type="hidden"  name="callback" value="myDis" />
				附件：
				<input type="file" name="upload" id="uploadP" value=""/>
				<input type="button" onclick="uploadFile();" style="width: 80px;" value="上传" />
			</form>
			下载地址 : <input type="text" id="downloadUrl" style="width:500px;" />
					  <input type="button" onclick="downloadFile();" style="width: 80px;" value="下载" />
			<iframe name="uploadIframe" frameborder=0 height=0 width=0></iframe><br>	
			
			<form name="delForm" id="delForm"  method="POST" >
			文件路径 : <input type="text" id="attaFilePath" name="attaFilePath" value="" ><br>
			文件名称 : <input type="text" id="attafileName" name="attafileName" value="" >
			<input type="button" onclick="deleteFile();" style="width: 80px;" value="删除" /><br>
			</form>
			
	</div>
</body>
